package com.NeuglsWorkStudio.UI.Dialog
{
	import com.NeuglsWorkStudio.Colors.HSL;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TFormExConfig;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TLabelConfig;
	import com.NeuglsWorkStudio.UI.TForm;
	import com.NeuglsWorkStudio.UI.TFormEx;
	
	import flash.display.DisplayObject;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class TDialog extends TFormEx
	{
		public static var Ok:String="OK";
		public static var Cancel:String="Cancel";
		public static var Yes:String="Cancel";
		public static var No:String="Cancel";
		public static var BaseColor:int=0x222222;
		
		public function TDialog(FormConfig:TFormExConfig)
		{
			super(FormConfig);
		}
		
		public static function SetButtonLanguage(S:Object):void{
			TDialog.Ok=S.Ok;
			TDialog.Cancel=S.Cancel;
			TDialog.Yes=S.Yes;
			TDialog.No=S.No;
		}
		
		public static function ShowMessage(Msg:String,Title:String):DisplayObject{
			var W:Number=300;
			var FormConfig:TFormExConfig=new TFormExConfig();
			var Components:Array=new Array();
			FormConfig.BaseColor=BaseColor;
			FormConfig.Caption=Title;
			FormConfig.CloseBtnTip='';
			FormConfig.Icon=null;
			FormConfig.Width=W;
			FormConfig.Height=GetTextHeight(Msg,W-20)+120;
			FormConfig.Name="formexdialog";
			FormConfig.Components=Components;
			
			var labelConfig:TLabelConfig=new TLabelConfig();
			labelConfig.Caption=Msg;
			labelConfig.Color=HSL.AddLightToColor(BaseColor,0.25);
			labelConfig.Size=14;
			labelConfig.Width=W-20;
			
			labelConfig.x=20;
			labelConfig.y=10;
			labelConfig.Name="msg";
			labelConfig.AutoWordWrap=true;
			Components.push({ComponentType:TForm.ctLable,ComponentConfig:labelConfig});
			
				
			return new TFormEx(FormConfig);
		}
		
		public static  function GetTextHeight(T:String,W:Number):Number{
			var f:TextField=new TextField();
			var fm:TextFormat=new TextFormat("Tahoma",12);
			f.defaultTextFormat=fm;
			f.multiline=true;
			f.wordWrap=true;
			f.text=T;
			f.width=W;
			var r:Number=f.textHeight;
			f=null;
			return r;
			
		}
	}
}